#include<bits/stdc++.h>
using namespace std;
int f[10000];
int main(void)
{
    int n, m;
    cin >> n >> m;
    vector<vector<pair<int, int>>>v(n + 1);
    vector<bool>visited(n + 1);
    int in[10000] = { 0 };
    for (int i = 0; i < m; i++)
    {
        int a, b, w;
        cin >> a >> b >> w;
        v[a].push_back({ b,w });
        in[b]++;
    }
    int ans = 0, flag = 0, con = 0;
    while (1)
    {
        flag = 0;
        int index = -1;
        for (int i = 0; i < n; i++)
        {
            if (in[i] == 0)
            {
                in[i]--;
                con++;
                index = i;
                flag = 1;
                break;
            }
        }
        if (index == -1)
            break;
        for (int i = 0; i < v[index].size(); i++)
        {
            in[v[index][i].first]--;
            f[v[index][i].first] = max(f[v[index][i].first], f[index] + v[index][i].second);
            ans = max(f[v[index][i].first], ans);
        }

    }
    if (con == n)
    {
        cout << ans;
    }
    else
    {
        cout << "Impossible";
    }



}